/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.simba.utils.tree;

/**
 *
 * @author ngonga
 */
public class DependencyReader {

    public static Tree getDependencies(String dependencies) {
        Tree result = new Tree();
        String lines[] = dependencies.split("\n");
        String split[];
        String d;
        String edgeType;
        for(int i=0; i<lines.length; i++)
        {
            if(lines[i].contains("(") && lines[i].contains(")"))
            {
                edgeType = lines[i].substring(0, lines[i].indexOf("("));
                d = lines[i].substring(lines[i].indexOf("(")+1, lines[i].lastIndexOf(")"));
                split = d.split(", ");
                //result.addEdge(split[0].substring(0, split[0].indexOf("-")), 
                //        split[1].substring(0, split[1].indexOf("-")), edgeType);
                result.addEdge(split[0], split[1], edgeType);
                        //System.out.println(result.elements);
                //System.out.println("added "+split[0] +" -> "+split[1]);
            }
        }
         
        return result;
    }

    public static void main(String args[]) {
        String s = "nsubj(happy-4, SAP-1)\n"+
"cop(happy-4, is-2)\n"+
"advmod(happy-4, really-3)\n"+
"aux(receive-6, to-5)\n"+
"xcomp(happy-4, receive-6)\n"+
"det(grant-8, this-7)\n"+
"dobj(receive-6, grant-8)\n";
        Tree t = getDependencies(s);
        t.ws = new WordScore();
        t.ws.loadSentiments("D:/Downloads/twitter_sentiment_list.csv");
        System.out.println(t.edges);
        //System.out.println(t.getModifiers("is-2"));        
        System.out.println(t.getSentiment("SAP", "subject"));
        //System.out.println(t.getElement("Limbe", 11, "There is a Limbe in Malawi and a Limbe in Cameroon."));
    }
}
